/*
 * @Author: Dorange.Wang
 * @Date: 2021-04-15 14:25:15
 * @LastEditors: wangming
 * @LastEditTime: 2022-07-15 14:19:42
 * @Description: file content
 */
// 应用相关信息
import { getHmtenantappNakedInfounique } from '@/apis/dev-centre/HmTenantAppController.js'
const state = {
  appInfo: {},
  fullscreen: false,
  pageFormData: {}
}
const mutations = {
  SET_APP_INFO(state, payload) {
    if (payload.icon) {
      try {
        const file = JSON.parse(payload.icon)
        if (file && file.accessUrl) {
          payload.icon = file
        }
      } catch (error) {
      }
    }
    if (payload.iconPro) {
      try {
        const file = JSON.parse(payload.iconPro)
        if (file && file.accessUrl) {
          payload.iconPro = file
        }
      } catch (error) {
      }
    }
    state.appInfo = payload
  },
  SET_FORM_DATA(state, formData) {
    state.pageFormData = Object.assign({}, state.pageFormData, formData)
    // console.log(state.pageFormData)
  }
}
const actions = {
  setRuleData({ commit }, formData) {
    commit('SET_FORM_DATA', formData)
  },
  async LOAD_APP_INFO({ commit, getters }) {
    if (!getters.APP_INFO.id) {
      const data = await getHmtenantappNakedInfounique()
      commit('SET_APP_INFO', data)
    }
    return getters.APP_INFO
  }
}
const getters = {
  getRuleFormData(state) {
    return state.pageFormData
  },
  APP_INFO(state) {
    return state.appInfo
  },
  getfullscreen() {
    return state.fullscreen
  }
}
document.addEventListener("fullscreenchange", () => {
  state.fullscreen = !!document.fullscreenElement
  if (!!document.fullscreenElement) return
  document.querySelectorAll('.fullscreen').forEach(el => {
    el.classList.remove("fullscreen")
  })
})
export default {
  getters,
  state,
  mutations,
  actions
}
